package com.study.view;

import android.os.Bundle;

import com.study.view.widget.BlockView;
import com.study.view.widget.CircularProgress;
import com.study.view.widget.RotateProgress;
import com.study.view.widget.TagsView;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;


public class WidgetActivity extends AppCompatActivity {

    CircularProgress progress;
    RotateProgress loading;
    BlockView blockView;
    TagsView tagsView;
    List<String> tagsList = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wieget);
        loading = findViewById(R.id.loading);
        onTagsData();
        initView();
    }

    private void onTagsData(){
        tagsList = new ArrayList<>();
        String [] data = getResources().getStringArray(R.array.tags);
        for (int i = 0; i < data.length; i++) {
            tagsList.add(data[i]);
        }
    }


    private void initView() {
        tagsView = findViewById(R.id.tagsView);
        tagsView.setTagsData(tagsList);

        progress = findViewById(R.id.progress);
        blockView = findViewById(R.id.blockView);
        progress.setOnClickListener(view->{
            progress.setStateProgress();
            loading.startLoading();
        });

        blockView.setOnClickListener(view->{

            new Thread(new Runnable() {
                @Override
                public void run() {

                    while (true){
                        try{
                            Thread.sleep(1000);
                        }catch (Exception e){

                        }
                        blockView.startBlock();
                    }


                }
            }).start();


        });
    }

    /**
     * 界面不可见时关闭view的动画
     */
    @Override
    protected void onStop() {
        super.onStop();
        progress.stopAnimator();
        loading.stopAnimator();
    }
}
